﻿using FlowCanvas;
using FlowCanvas.Nodes;
using UnityEngine;

namespace Yoozoo.Gameplay.Liberty.Nodes
{
    public class GetBlueprintPoint : PureFunctionNodeBase
    {
        public virtual BluePrintPoint Invoke(string pointName)
        {
            return BlueprintUtils.GetBlueprintPoint(pointName);
        }
        
        protected override void OnRegisterPorts(FlowNode node)
        {
            var p1 = node.AddValueInput<string>(parameters[0].Name);
            node.AddValueOutput<Vector3>("position", () =>
            {
                BluePrintPoint t = Invoke(p1.value);
                if (t!=null) return Invoke(p1.value).position;
                return Vector3.zero;
            });
            node.AddValueOutput<Quaternion>("rotation", () =>
            {
                BluePrintPoint t = Invoke(p1.value);
                if (t!=null) return Invoke(p1.value).rotation;
                return Quaternion.identity;
            });
            node.AddValueOutput<Vector3>("lossyScale", () =>
            {
                BluePrintPoint t = Invoke(p1.value);
                if (t!=null) return Invoke(p1.value).lossyScale;
                return Vector3.zero;
            });
            node.AddValueOutput<Vector3>("eulerAngles", () =>
            {
                BluePrintPoint t = Invoke(p1.value);
                if (t!=null) return Invoke(p1.value).eulerAngles;
                return Vector3.zero;
            });
        }
    }
}